/// <reference types="@cloudflare/workers-types" />

import { Router, RouterHandler } from '@tsndr/cloudflare-worker-router';

import { OpenaiChatHandler, WebhookFeishuEventHandler } from './handler';

const router = new Router();

router.options('/v1/chat/completions', OpenaiChatHandler);
router.post('/v1/chat/completions', OpenaiChatHandler);

router.post('/webhook/feishu-event', WebhookFeishuEventHandler);

export default {
	async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
		return router.handle(request, env, ctx);
	},
};
